package com.frinder.official.akka.mailbox;

import akka.actor.PoisonPill;
import akka.dispatch.ControlMessage;
import com.frinder.official.spring.MyBaseActor;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * Created by frinder on 2017/9/28.
 */
@Component
@Scope("prototype")
public class ControlAwareMailboxActor extends MyBaseActor {

    @Override
    public void preStart() throws Exception {
        super.preStart();
        Object[] msgs = {"foo", "bar", new MyControlMessage(), PoisonPill.getInstance()};
        for (Object msg : msgs) {
            getSelf().tell(msg, getSelf());
        }
    }

    @Override
    public Receive createReceive() {
        return receiveBuilder().matchAny(message -> {
            log.info("####################");
            log.info(message.toString());
            log.info("####################");
        }).build();
    }

    public class MyControlMessage implements ControlMessage {
    }
}
